package it.poste.il.compensatore.entities;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name="messagedata")
public class MessageBody extends BaseEntity {

	private static final long serialVersionUID = -1965501816301400929L;

	@Lob
	private String inputMessage;
	
	@OneToOne(fetch=FetchType.LAZY)
	private Message message;
	
	public Message getMessage() {
		return message;
	}
	
	public void setMessage(Message message) {
		this.message = message;
	}
	
	public String getInputMessage() {
		return inputMessage;
	}
	
	public void setInputMessage(String inputMessage) {
		this.inputMessage = inputMessage;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((inputMessage == null) ? 0 : inputMessage.hashCode());
		result = prime * result
				+ ((message == null) ? 0 : message.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MessageBody other = (MessageBody) obj;
		if (inputMessage == null) {
			if (other.inputMessage != null)
				return false;
		} else if (!inputMessage.equals(other.inputMessage))
			return false;
		if (message == null) {
			if (other.message != null)
				return false;
		} else if (!message.equals(other.message))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "MessageBody [message=" + message + ", inputMessage="
				+ inputMessage + "]";
	}

}
